home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-09-20 | 4.3 KB | 136 lines | [TEXT/MMCC] |
- //
- // ADB Key Spy • Pete Gontier • gurgle@apple.com
- // Macintosh Developer Technical Support
- // © 1995 Apple Computer, Inc.
- //
- // This module provides something of a replacement for GetKeys by
- // maintaining a key map reflecting the state of each keyboard
- // attached to the Mac via ADB. (This means it won't work with any
- // Mac earlier than an SE.)
- //
- // The module is intended to solve a problem a game developer
- // was having with the Adjustable Keyboard, which appears on ADB as
- // two keyboards. The ROM keyboard driver has one map and clears it
- // whenever there is a key state change on a new keyboard.
- // Consequently, it was impossible for said developer to allow
- // users to steer on the numeric key pad and fire with the space bar.
- //
- // Although this module does maintain a map for each keyboard, the
- // module does not provide an API for polling individual keyboards.
- // You can only find out if a key with a given key code is being
- // held down on any keyboard. If you need this functionality, it
- // should be pretty simple to add. (That's why you get the source...)
- //
- // Finally, this package has the limitation that if you call
- // AKS_AcquireKeyboards while a key is being held down,
- // AKS_IsKeyDown will not return true for that key until the key
- // is released and held down again. This is the peril of not
- // being the ROM keyboard driver.
- //
-
- #pragma once
-
- #ifndef __DESKBUS__
- # include <DeskBus.h>
- #endif
-
- //
- // kMaxKeyCode
- //
- // GetKeys returns four 32-bit quantities for its key map, and with
- // each bit corresponding to a key, that 32*4==128 keys. I don't know
- // if keyboards are capable of supporting more keys, but it's unlikely
- // anybody cares about key codes that high simply because GetKeys
- // can't report them. We use 127 because key codes start at 0.
- //
-
- static const unsigned char kMaxKeyCode = 127;
-
- //
- // tKeyboardInfo
- //
- // This structure describes each keyboard discovered during AKS_AcquireKeyboards.
- // In it we store info from the service routine for the keyboard before we replace it,
- // plus a key map. We use a byte for each entry in the key map mostly for historical
- // reasons. (There used to be one key map for all keyboards; each entry was a counter.)
- // Now it has a byte per entry simply because I am too lazy to write the bit-twiddling
- // code to make it one bit per entry.
- //
- // We maintain a simple linked list of these structures. Client code doesn't need to
- // worry about this structure; it's just here for the benefit of the code resource.
- //
-
- #if PRAGMA_ALIGN_SUPPORTED
- # pragma options align=mac68k
- #endif
-
- typedef struct
- {
- unsigned char raw;
- Boolean noXor, Xor;
- unsigned char bits;
- unsigned char pstring [ ];
- }
- tKeyMapResourceException;
-
- typedef struct // for corroboration, see "SysTypes.r"
- {
- unsigned short id;
- unsigned short vers;
- unsigned char map [kMaxKeyCode + 1];
- unsigned short exceptionCount;
- tKeyMapResourceException exceptions [ ];
- }
- tKeyMapResource, *tKeyMapResourceP, **tKeyMapResourceH;
-
- typedef struct tKeyboardInfo
- {
- ADBServiceRoutineUPP dbServiceRtPtr;
- Ptr dbDataAreaAddr;
- unsigned char virtualKeyMap [kMaxKeyCode + 1];
- tKeyMapResourceH keyMapResH;
- struct tKeyboardInfo *next;
- }
- tKeyboardInfo;
-
- #if PRAGMA_ALIGN_SUPPORTED
- # pragma options align=reset
- #endif
-
- //
- // AKS_AcquireKeyboards
- //
- // Walks the ADB device list and patches the service routine
- // of each keyboard so that an extra (internal) key map is maintained.
- // A block of memory is allocated via NewPtr for each keyboard.
- //
- // You will probably want to call this function when your app
- // starts and on resume events.
- //
-
- pascal OSErr AKS_AcquireKeyboards (void);
-
- //
- // AKS_RelinquishKeyboards
- //
- // Walks the private internal list of patched ADB keyboard
- // service routines and unpatches them.
- //
- // You will probably want to call this function when your app
- // quits and on suspend events. If you patch ExitToShell for
- // cleanup during emergency exits, you will want to call this
- // in your patch.
- //
-
- pascal OSErr AKS_RelinquishKeyboards (void);
-
- //
- // AKS_IsKeyDownAnywhere
- //
- // Tests all key maps to see whether the key corresponding to
- // the given key code is down. Pass a value from 0 to 127; higher
- // values always produce false.
- //
-
- pascal Boolean AKS_IsKeyDownAnywhere (unsigned char keyCode);
-